<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- <link rel="shortcut icon" href="img/logo.ico" /> -->
    <title>店铺管理</title>
    <link href="plugin/date/date.css" rel="stylesheet">
    <link href="bootstrap/css/bootstrap3.min.css" rel="stylesheet">
    <!-- <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> -->
    <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/nav.css" />
</head>

<body>
    <!--导航-->
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
                <a class="navbar-brand" href=""><img src="images/admin_logo.png" alt=""></a>
            </div>

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
                <ul class="nav navbar-nav" id="nav">

                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">欢迎您：<span id="uname"></span><span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="change_pass.html">修改密码</a></li>
                            <li><a id="loginOut" href="#">退出登陆</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container-fluid">
        <div class="row bcert-box">
            <ol class="breadcrumb">
                <li><a href="javascript:;">主页</a></li>
                <li>店铺管理</li>
                <li class="active">店铺管理</li>
            </ol>
            <form class="form-inline">
                <div class="form-group">
                    <label for="exampleInputName2">所属等级</label>&nbsp;&nbsp;
                    <select class="form-control" id="storeGradeSel">

                    </select>
                </div>&nbsp;&nbsp;
                <div class="form-group">
                    <label for="">店主</label>&nbsp;&nbsp;
                    <input type="text" class="form-control" id="shopKeeper" placeholder="">&nbsp;&nbsp;
                </div>
                <div class="form-group">
                    <label for="exampleInputName2">店铺状态</label>&nbsp;&nbsp;
                    <select class="form-control" id="storeClassSel">
                        <option value="">请选择</option>
                        <option value="1">开启</option>
                        <option value="0">关闭</option>
                    </select>
                </div>&nbsp;&nbsp;
                <div class="form-group">
                    <label for="">店铺</label>&nbsp;&nbsp;
                    <input type="text" class="form-control" id="shopIpt" placeholder="">&nbsp;&nbsp;
                </div>
                <button type="button" class="btn btn-default" id="btnSearch"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>&nbsp;&nbsp;&nbsp;&nbsp;
                <button type="button" name="button" id="btnInsertStroe" class="btn btn-primary" data-toggle="modal" data-target="#insertStroeModal">新增店铺</button>
            </form>
            <div class="table">
                <table class="table table-bordered table-striped" id="integralList">

                </table>
            </div>
        </div>
        <!-- 分页 -->
        <nav aria-label="...">
            <div class="">
                <span id="pageNum">共&nbsp;<strong></strong>&nbsp;页&nbsp;/&nbsp;</span><span id="totalNum">&nbsp;<strong>0</strong>&nbsp;条数据</span>
            </div>
            <ul id="example"></ul>
        </nav>
    </div>

    <!-- 编辑 -->
    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="entinfo">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">编辑</h4>
                </div>
                <div class="modal-body" style="overflow:auto">
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">id</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" readonly="readonly" class="form-control" id="partner_id" placeholder="id"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">合作方名称</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" readonly="readonly" class="form-control" id="partner_name" placeholder="合作方等级名称"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">金牌小卫士每月新增数量（人）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="quantity" placeholder="金牌小卫士每月新增数量"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">营收（元）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="revenue" placeholder="营收"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">完成业绩分成比例（%）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="complete_reward" placeholder="完成业绩分成比例"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">未完成业绩分成比例（%）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="unfinished_bonus" placeholder="未完成业绩分成比例"></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="entBtn">确认提交</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>


    <!-- 新增店铺 -->
    <div class="modal fade" tabindex="-1" role="dialog" id="insertStroeModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">新增店铺</h4>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <label for="">店铺名称：</label>
                            <input type="text" class="form-control" id="" placeholder="请填写店铺名称" name="storeName">
                        </div>
                        <div class="form-group">
                            <label for="">手机号：</label>
                            <input type="text" class="form-control" id="" placeholder="请填写手机号" name="mobile">
                        </div>
                        <div class="form-group">
                            <label for="">用户名：</label>
                            <input type="text" class="form-control" id="" placeholder="请填写用户名" name="sellerName">
                        </div>
                        <div class="form-group">
                            <label for="">登录密码：</label>
                            <input type="password" class="form-control" id="" placeholder="请填写登录密码" name="storePwd">
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="btnSave">保存</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
</body>
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="plugin/layer/layer.js"></script>
<script type="text/javascript" src="js/cookie.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script src="./js/ajax.js" charset="utf-8"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-paginator.js"></script>
<script type="text/javascript" src="plugin/date/date.js"></script>
<script type="text/javascript" src="plugin/date/date.zh-CN.js"></script>
<script src="./js/jquery.cookie.js" charset="utf-8"></script>
<script>
    $("document").ready(function() {
        //integralListPaga()
        // inputEmpty()
        tableList()
    })

var pageUrls = serverURL + '/platform/queryStoreList';
    function tableList() {

        data = {
            // 'member':$('#member').val(),
            // 'memberType':$('#memberType').val(),
            // 'inviterId':$('#inviterId').val(),
            // 'memberState':$('#memberState').val(),
            // 'startTime':$('#startTime').val(),
            // 'endTime':$('#endTime').val(),
            'page': page,
            'pageSize': pagesize,
            'sgId':$('#storeGradeSel').val(),
            'storeState':$('#storeClassSel').val(),
            'storeName':$('#shopIpt').val(),
            'sellerName':$('#shopKeeper').val(),
        }
        data.page = 1
        ajax(
            pageUrls,
            data,
            pageNumList,
            'post',
            'json'
        )
    }

    //数据渲染
    function OpendList(res) {
        var res = res.data;
        var result = '';
        $('#integralList').empty();
        $('#integralList').append(
            '<tr>' +
            '<th>店铺</th>' +
            '<th>店主账号</th>' +
            '<th>店主卖家账号</th>' +
            '<th>所属等级</th>' +
            '<th>有效期至</th>' +
            '<th>状态</th>' +
            '<th>操作</th>' +
            '</tr>'
        );
        for (var i = 0; i < res.list.length; i++) {
            //var time = getMyDate(data.list[i].createTime);
            var storeStateCode = res.list[i].storeState;
            var storeStateDesc = '';
            switch (storeStateCode) {
                case '0':
                    storeStateDesc = '关闭';
                    break;
                case '1':
                    storeStateDesc = '开启';
                    break;
                case '2':
                    storeStateDesc = '审核中';
                    break;
                default:
                    break;
            }
            result +=
                '<tr>' +
                '<td>' + res.list[i].storeName + '</td>' +
                '<td>' + res.list[i].memberName + '</td>' +
                '<td>' + res.list[i].sellerName + '</td>' +
                '<td>' + res.list[i].sgName + '</td>' +
                '<td>' + res.list[i].closeTime + '</td>' +
                '<td>' + storeStateDesc + '</td>' +
                '<td class="text-center">' +
                '<a class="btn btn-default btn-sm" href="shop_manage_view.html?id=' + res.list[i].storeId + '" role="button" id="btnView">查看</a>&nbsp;&nbsp;' +
                '<a class="btn btn-primary btn-sm" href="shop_manage_editshop.html?id=' + res.list[i].storeId + '" role="button" id="btnEdit">编辑</a>&nbsp;&nbsp;' +
                '<a class="btn btn-primary btn-sm" href="shop_edit_category.html?id=' + res.list[i].storeId + '" role="button">经营类目</a>&nbsp;&nbsp;' +
                '<button type="button" data-id="' + res.list[i].storeId + '" class="btn btn-danger btn-sm listDel">删除</button>&nbsp;&nbsp;' +
                '</td>' +
                '</tr>'
        }
        $('#integralList').append(result);
        // $('#btnEdit').click(function () {
        //     var cokstoreId = $(this).attr('data-storeId')
        //     $.cookie('cokstoreId', cokstoreId, {
        //         expires: 1
        //     });
        // })
    }


    //删除
    $(document).on('click', '.listDel', function() {
        var id = $(this).attr('data-id')
        layer.confirm('确定要删除这条信息吗？', {
            btn: ['确定', '取消'] //按钮
        }, function() {
            deleteList(id)
        }, function() {});
    })
    //详情
    $(document).on('click', '.listEnt', function() {
        var id = $(this).attr('data-id')
        $.ajax({
            url: serverURL + '/member/queryPartnerLevelByPrimaryKey',
            type: "post",
            dataType: "json",
            data: {
                'partner_id': id,
            },
            success: function(data) {
                console.log(data.msg)
                if (data.code == 400) {
                    alert("登陆超时请重新登陆")
                    window.location.href = "login.html";
                } else if (data.code == 200) {
                    $('#partner_id').val(data.data.partner_id)
                    $('#partner_name').val(data.data.partner_name)
                    $('#quantity').val(data.data.quantity)
                    $('#revenue').val(data.data.revenue)
                    $('#complete_reward').val(data.data.complete_reward)
                    $('#unfinished_bonus').val(data.data.unfinished_bonus)
                    integralListPaga();
                }
            }
        });
    })

    //修改
    $('#entBtn').click(function() {
        $.ajax({
            url: serverURL + '/member/savePartnerLevel',
            type: "post",
            dataType: "json",
            data: {
                'partner_id': $('#partner_id').val(),
                'partner_name': $('#partner_name').val(),
                'quantity': $('#quantity').val(),
                'revenue': $('#revenue').val(),
                'complete_reward': $('#complete_reward').val(),
                'unfinished_bonus': $('#unfinished_bonus').val()
            },
            success: function(data) {
                console.log(data.msg)
                layer.msg(data.msg)
                if (data.code == 400) {
                    alert("登陆超时请重新登陆")
                    window.location.href = "login.html";
                } else if (data.code == 200) {
                    $('#entinfo').modal('hide')
                    integralListPaga();
                }
            }
        });
    })

    //删除
    function deleteList(id) {
        var url = serverURL + '/platform/deleteStoreById';
        data = {
            'storeId': id
        }
        var cbk = function(res) {
            location.reload()
        }
        ajax(
            url,
            data,
            cbk,
            'post',
            'json'
        )
    }

    // $('#btnInsertStroe').click(function() {
    //     $('#insertStroeModal').modal('show');
    // })
    $('#btnSave').click(function() {
        if ($('input[name="storeName"]').val() == '') {
            layer.msg('请填写店铺名称');
            return;
        }
        if ($('input[name="mobile"]').val() == '') {
            layer.msg('请填写手机号');
            return;
        }
        if ($('input[name="sellerName"]').val() == '') {
            layer.msg('请填写用户名');
            return;
        }
        if ($('input[name="storePwd"]').val() == '') {
            layer.msg('请填写登录密码');
            return;
        }

        var url = serverURL + '/platform/insertStroe';
        data = {
            'storeName': $('input[name="storeName"]').val(),
            'mobile': $('input[name="mobile"]').val(),
            'sellerName': $('input[name="sellerName"]').val(),
            'storePwd': $('input[name="storePwd"]').val()
        }
        var cbk = function(res) {
            setTimeout(function() {
                layer.msg('添加店铺成功')
            }, 2000);
            location.reload()
        }
        ajax(
            url,
            data,
            cbk,
            'post',
            'json'
        )
    })

    storeGradeSelInit()

    function storeGradeSelInit() {
        var url = serverURL + '/platform/queryStoreGrade';
        data = {

        }
        var cbk = function(res) {
            console.log(res);
            var data = res.data;
            $('#storeGradeSel').append('<option value="">请选择</option>')
            for (i in data) {
                $('#storeGradeSel').append('<option value="' + data[i].sgId + '">' + data[i].sgName + '</option>')
            }
        }
        ajax(
            url,
            data,
            cbk,
            'post',
            'json'
        )
    }

    $('#btnSearch').click(function () {
        tableList()
    })
</script>
</html>
